package com.jingzhi.huimiao;

import com.jingzhi.huimiao.bean.WordInfo;
import com.jingzhi.huimiao.utils.DataStoreUtil;
import com.jingzhi.huimiao.utils.SQLdm;

import android.app.Activity;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

public class WordDetailsActivity extends Activity implements OnClickListener {

	private TextView tv_wdetail_word;
	private TextView tv_wdetail_soundmark;
	private TextView tv_wdetail_translation;
	private TextView tv_wdetail_exaptrans;
	private ImageView iv_wdetail_sound;
	private SQLiteDatabase db;
	private Cursor wordInfoCur;
	private LinearLayout iv_back_tomain;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_word_details);
		
		initview();
		
		// 打开数据库输出流
		SQLdm s = new SQLdm();
		db = s.openDatabase(getApplicationContext());
		
		String word = DataStoreUtil.getString(WordDetailsActivity.this, "xiangqing");
		wordInfoCur = db.rawQuery("select * from word where word_name='"+word+"';", null);
		WordInfo wordinfo = new WordInfo();
		if(wordInfoCur.moveToFirst()){
			wordinfo.wname = wordInfoCur.getString(wordInfoCur.getColumnIndex("word_name"));
			wordinfo.wsoundm = wordInfoCur.getString(wordInfoCur.getColumnIndex("word_soundmark"));
			wordinfo.wtrans = wordInfoCur.getString(wordInfoCur.getColumnIndex("word_translation"));
			wordinfo.wex_tr = wordInfoCur.getString(wordInfoCur.getColumnIndex("word_example_translation"));
			wordinfo.wexamp = wordInfoCur.getString(wordInfoCur.getColumnIndex("word_example"));
		}
		
		if(wordInfoCur!=null){
			wordInfoCur.close();
		}if(db!=null){
			db.close();
		}
		
		tv_wdetail_word.setText(wordinfo.wname);
		tv_wdetail_soundmark.setText(wordinfo.wsoundm);
		tv_wdetail_translation.setText(wordinfo.wtrans);
		tv_wdetail_exaptrans.setText(wordinfo.wexamp+wordinfo.wex_tr);
		
		iv_back_tomain.setOnClickListener(this);
	}

	private void initview() {
		tv_wdetail_word = (TextView) findViewById(R.id.tv_wdetail_word);
		tv_wdetail_soundmark = (TextView) findViewById(R.id.tv_wdetail_soundmark);
		tv_wdetail_translation = (TextView) findViewById(R.id.tv_wdetail_translation);
		tv_wdetail_exaptrans = (TextView) findViewById(R.id.tv_wdetail_exaptrans);
		iv_wdetail_sound = (ImageView) findViewById(R.id.iv_wdetail_sound);
		iv_back_tomain = (LinearLayout) findViewById(R.id.iv_back_tomain);
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.iv_back_tomain:
			finish();
			break;

		default:
			break;
		}
	}
}
